package com.hl.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Documentation;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.nio.file.Paths;
import java.util.ArrayList;

/**
 * @author Liu Huan
 */
@Configuration  //配置swagger
@EnableSwagger2 //开启swagger2  访问 http://localhost:8080/swagger-ui.html
public class SwaggerConfig {
	
	
	@Bean
	public Docket docket1(){
		return new Docket((DocumentationType.SWAGGER_2)).groupName("AA");
	}
	
	@Bean   //配置 swagger 的 bean 实例
	public Docket docket() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.groupName("HL")    // 开发人员的名字，接口分组显示
				//.enable(false)    // 关闭 swagger，默认为 true
				.select()   // 配置扫描的接口情况
				//    RequestHandlerSelectors.basePackage() 配置扫描 指定包的 接口
				//    RequestHandlerSelectors.any()         配置扫描 全部
				//    RequestHandlerSelectors.none()        配置扫描 全不扫描
				.apis(RequestHandlerSelectors.basePackage("com.hl.controller"))
				//.paths(PathSelectors.ant("/liuhuan/**"))  // 过滤路径：只搜索 /liuhuan/** 的接口
				.build();
	}
	
	//配置 swagger 基本信息
	private ApiInfo apiInfo(){
		//作者信息
		Contact contact = new Contact("Liu Huan", "", "3297782322@qq.com");
		return new ApiInfo(
				"Swagger", 
				"Api Documentation", 
				"v1.0", 
				"urn:tos",
				contact, 
				"Apache 2.0", 
				"http://www.apache.org/licenses/LICENSE-2.0", 
				new ArrayList());
	}
	
}
